<?php

class Opinion extends \Eloquent
{

    protected $guarded = [
        'id',
    ];

    use SoftDeletingTrait;
    protected $dates = ['deleted_at'];

    public static function boot()
    {
        parent::boot();

        static::created(function ($evaluation) {
            SiteStatus::newOpinion();
        });
    }

    public function votes()
    {
        return $this->morphMany('Vote', 'votable');
    }

    public function user()
    {
        return $this->belongsTo('User');
    }

    public function report()
    {
        return $this->belongsTo('Report');
    }

    public function scopeWhose($query, $user_id)
    {
        return $query->where('user_id', '=', $user_id)->with('lab');
    }

    public function scopeRecent($query)
    {
        return $query->orderBy('created_at', 'desc');
    }
}
